package com.xxxx.yeb.controller;


import com.xxxx.yeb.pojo.Department;
import com.xxxx.yeb.pojo.RespBean;
import com.xxxx.yeb.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Hanqiang
 * @since 2021-04-18
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation(value = "获取所有部门")
    @GetMapping("/")
    public List<Department> getAllDepartments(){
        return departmentService.getAllDepartments();
    }


    /**
     * 添加部门存在BUG 不能够添加 -->数据库字符集的原因
     * @param dept
     * @return
     */
    @ApiOperation(value = "添加部门")
    @PostMapping("/")
    public RespBean addDep(@RequestBody Department dept){
        return departmentService.addDep(dept);
    }

    /**
     * 存在BUG，无法查看
     * @param id
     * @return
     */
    @ApiOperation(value = "删除部门")
    @DeleteMapping("/{id}")
    public RespBean deleteDep(@PathVariable Integer id){
        return departmentService.deleteDep(id);
    }


}
